package main

import (
	"IMServices/MessageService/MessageOrder"
	"IMServices/MessageService/ServerManagerCenter"
	ServiceNetIO2 "IMServices/NetIO/ServiceNetIO"
	"time"
)

var server ServiceNetIO2.ServerClient

func handleFunc(msg chan ServiceNetIO2.RequestBuffer, finish chan bool) {
	for {
		select {
		case data := <-msg:
			println(data.Request.OrderId)
			//启动业务函数go程
			go MessageOrder.Test(data)
		case <-finish:
			return
		}
	}

}

var index int64

func sendTest() {
	index = index + 1
	// 测试发送 gRPC 请求
	request := ServiceNetIO2.RequestBuffer{
		TargetServer: "StatusServer",
		Request: ServiceNetIO2.MessageRequest{
			Header:     []byte{},
			ServerName: "MessageServer",
			OrderId:    index,
			EncodeType: "",
			Body:       []byte{},
		},
	}
	ServiceNetIO2.AddNewMessage(request)
	request.TargetServer = "LoginServer"
	ServiceNetIO2.AddNewMessage(request)
}
func main() {
	addr := string("localhost:13333")
	//开始监听，并且打开go程函数
	ServerManagerCenter.Server.Listen.StartServiceNet(addr, handleFunc, 1000)

	ServerManagerCenter.Server.Connect("StatusServer", []string{"localhost:12222"})

	ServerManagerCenter.Server.Connect("LoginServer", []string{"localhost:11111"})

	//开始监听，并且打开go程函数
	go func() {
		for {
			time.Sleep(time.Second * 1)
			sendTest()
		}
	}()
	select {}

}
